package com.isoft.airportsystem.mapper.system;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.airportsystem.entity.system.UserRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

// UserRoleMapper.java
@Mapper
public interface UserRoleMapper extends BaseMapper<UserRole> {

    /**
     * 批量新增用户角色关联
     * @param userId  用户ID
     * @param roleIds 角色ID列表
     * @return 插入的行数
     */
    @Insert({
            "<script>",
            "INSERT INTO sys_user_role (user_id, role_id) VALUES ",
            "<foreach collection='roleIds' item='roleId' separator=','>",
            "(#{userId}, #{roleId})",
            "</foreach>",
            "</script>"
    })
    Integer batchInsert(
            @Param("userId") Long userId,
            @Param("roleIds") List<Long> roleIds
    );
}